package com.iotek.ssm.service.impl;

import com.iotek.ssm.mapper.ApplySheetMapper;
import com.iotek.ssm.mapper.EducationMapper;
import com.iotek.ssm.mapper.PoliticsMapper;
import com.iotek.ssm.mapper.UserMapper;
import com.iotek.ssm.pojo.*;
import com.iotek.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private EducationMapper educationMapper;

    @Autowired
    private PoliticsMapper politicsMapper;

    @Autowired
    private ApplySheetMapper applySheetMapper;

    public User findByPhone(String phone) throws Exception {
        return userMapper.findUserByPhone(phone);
    }

    public void saveUser(User user) throws Exception {
        userMapper.addUser(user);
    }

    public void updateUser(User user) throws Exception {
        userMapper.updateUser(user);
    }

    public List<Education> findEducations() throws Exception {
        return educationMapper.findEducations();
    }

    public List<PoliticsStatus> findPolitics() throws Exception {
        return politicsMapper.findPolitics();
    }

    public Resume findResume(User user) throws Exception {
        return userMapper.findResume(user);
    }

    //保存简历的同时将应聘信息保存
    public void saveResume(Resume resume) throws Exception {
        userMapper.saveResume(resume);
        ApplySheet applySheet = new ApplySheet();
        applySheet.setResume(resume);
        applySheet.setPostTime(new Date());
        applySheetMapper.addApplyInformation(applySheet);
    }

    public void updateResume(Resume resume) throws Exception {
        userMapper.updateResume(resume);
    }
}
